package com.cleaningcloud.common.security.utils;

import com.cleaningcloud.common.core.utils.SpringUtils;
import com.cleaningcloud.common.core.utils.StringUtils;
import com.cleaningcloud.common.redis.service.RedisService;

import java.util.Collection;

/**
 * 科目工具类
 *
 * @author ruoyi
 */
public class SubjectUtils {

    /**
     * 设置字典缓存
     *
     * @param key 参数键
     * @param dictDatas 字典数据列表
     */
    public static void setSubjectCache(String key, String value)
    {
        SpringUtils.getBean(RedisService.class).setCacheObject(getCacheKey(key), value);
    }

    /**
     * 获取字典缓存
     *
     * @param key 参数键
     * @return dictDatas 字典数据列表
     */
    public static String getSubjectCache(String key)
    {
        String value = SpringUtils.getBean(RedisService.class).getCacheObject(getCacheKey(key));
        if (StringUtils.isNotNull(value))
        {
            return value;
        }
        return null;
    }

    /**
     * 删除指定字典缓存
     *
     * @param key 字典键
     */
    public static void removeSubjectCache(String key)
    {
        SpringUtils.getBean(RedisService.class).deleteObject(getCacheKey(key));
    }

    /**
     * 清空字典缓存
     */
    public static void clearSubjectCache()
    {
        Collection<String> keys = SpringUtils.getBean(RedisService.class).keys("SUBJECT:*");
        SpringUtils.getBean(RedisService.class).deleteObject(keys);
    }

    /**
     * 设置cache key
     *
     * @param configKey 参数键
     * @return 缓存键key
     */
    public static String getCacheKey(String configKey)
    {
        return "SUBJECT:" + configKey;
    }
}